{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"UTF-8\""
      ]
     },
     "execution_count": 52,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "### pry-docの読み込み\n",
    "require \"/root/jupyter/vendor/bundle/ruby/2.3.0/gems/pry-doc-0.10.0/lib/pry-doc\"\n",
    "#require \"/Users/ftakao2007/jupyter/vendor/bundle/ruby/2.3.0/gems/pry-doc-0.10.0/lib/pry-doc\"\n",
    "### エンコーディングをUTF-8に設定\n",
    "Encoding.default_external = \"UTF-8\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 概要\n",
    "\n",
    "* rspecの使い方について"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# インストール\n",
    "\n",
    "* Gemfile\n",
    "\n",
    "```\n",
    "================================================\n",
    "# frozen_string_literal: true\n",
    "source \"https://rubygems.org\"\n",
    "gem 'rspec'\n",
    "================================================\n",
    "```\n",
    "\n",
    "* bundler\n",
    "    * `$ bundle install --path vendor/bundle`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "# frozen_string_literal: true\n",
      "source \"https://rubygems.org\"\n",
      "\n",
      "# gem \"rails\"\n",
      "\n",
      "gem 'ruby-ldap', '~> 0.9.11'\n",
      "gem 'rspec'\n",
      "\n",
      "Don't run Bundler as root. Bundler can ask for sudo if it is needed, and\n",
      "installing your bundle as root will break this application for all non-root\n",
      "users on this machine.\n",
      "Using diff-lcs 1.3\n",
      "Using rspec-support 3.6.0\n",
      "Using ruby-ldap 0.9.19\n",
      "Using bundler 1.14.6\n",
      "Using rspec-core 3.6.0\n",
      "Using rspec-expectations 3.6.0\n",
      "Using rspec-mocks 3.6.0\n",
      "Using rspec 3.6.0\n",
      "Bundle complete! 2 Gemfile dependencies, 8 gems now installed.\n",
      "Bundled gems are installed into /root/git_jupyter_notebook/Ruby/vendor/bundle.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "### Gemfileの確認\n",
    "File.open(\"Gemfile\") do |file|\n",
    "  puts file.read\n",
    "end\n",
    "\n",
    "### Jupyter上からインストールする場合はFullPATHで指定\n",
    "puts `bundle install --gemfile /root/git_jupyter_notebook/Ruby/Gemfile --path /root/git_jupyter_notebook/Ruby/vendor/bundle`"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# テスト実行"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "Mail\n",
      "  #score\n",
      "    returns 0 for an all gutter mail\n",
      "\n",
      "Finished in 0.00077 seconds (files took 0.05612 seconds to load)\n",
      "1 example, 0 failures\n",
      "\n",
      "\n"
     ]
    }
   ],
   "source": [
    "### specディレクトリの作成\n",
    "Dir.mkdir('spec') unless Dir.exist?('spec')\n",
    "#puts Dir.glob('spec')\n",
    "#puts Dir.open(\".\").each{|file| puts file}\n",
    "\n",
    "### spec/mail_spec.rbファイルの作成\n",
    "File.open(\"spec/mail_spec.rb\", \"w\") do |file|\n",
    "file.write <<-EOS\n",
    "require './spec/mail'\n",
    "\n",
    "RSpec.describe Mail do\n",
    "  describe \"#score\" do\n",
    "    it \"returns 0 for an all gutter mail\" do\n",
    "      mail = Mail.new\n",
    "      20.times { mail.roll(0) }\n",
    "      expect(mail.score).to eq(0)\n",
    "    end\n",
    "  end\n",
    "end\n",
    "EOS\n",
    "end\n",
    "\n",
    "### spec/mail.rbファイルの作成\n",
    "File.open(\"spec/mail.rb\", \"w\") do |file|\n",
    "file.write <<-EOS\n",
    "class Mail\n",
    "  def roll(pins)\n",
    "  end\n",
    "\n",
    "  def score\n",
    "    0\n",
    "  end\n",
    "end\n",
    "EOS\n",
    "end\n",
    "\n",
    "### テスト実行\n",
    "puts `bundle exec rspec spec/mail_spec.rb --color --format doc`"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Ruby 2.3.3",
   "language": "ruby",
   "name": "ruby"
  },
  "language_info": {
   "file_extension": ".rb",
   "mimetype": "application/x-ruby",
   "name": "ruby",
   "version": "2.3.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
